package com.ruoyi.web.controller.app;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.biz.UserRateBizService;
import com.ruoyi.system.domain.Cash;
import com.ruoyi.system.domain.UserRate;
import com.ruoyi.system.dto.UserSetRateDto;
import com.ruoyi.system.service.UserRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理后台:用户费率接口")
@RestController
@RequestMapping("/app/userRate")
public class UserRateController extends AppController {
    @Resource
    private UserRateService userRateService;

    @Resource
    private UserRateBizService userRateBizService;


    @ApiOperation(value = "获取登录用户费率")
    @RequestMapping("getLoginUserRate")

    public ResponseResult getLoginUserRate() {
        Long userId = getUserId();
        UserRate userRate = new UserRate();
        userRate.setUserId(userId);
        PageDomain pageDomain=new PageDomain();
        pageDomain.setPageSize(100);
        pageDomain.setOrderByColumn("channel_code");
        pageDomain.setIsAsc("asc");
        List<UserRate> list = userRateService.findList(userRate,pageDomain);
        return this.setSuccessResult(list);
    }

    @ApiOperation(value = "获取登录用户费率")
    @RequestMapping("getRateByUserId")

    public ResponseResult getRateByUserId(Long userId) {

        UserRate userRate = new UserRate();
        userRate.setUserId(userId);
        PageDomain pageDomain=new PageDomain();
        pageDomain.setPageSize(100);
        pageDomain.setOrderByColumn("channel_code");
        pageDomain.setIsAsc("asc");
        List<UserRate> list = userRateService.findList(userRate,pageDomain);
        return this.setSuccessResult(list);
    }

    @Log(title = "设置用户通道费率", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "设置用户通道费率")
    @PostMapping("setRate")
    public ResponseResult<List<Cash>> setRate(@RequestBody  UserSetRateDto userSetRateDto) {
        Long userId = getUserId();
        userRateBizService.setRate(userId, userSetRateDto);
        return this.setSuccessResult();
    }


}
